home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / admin / uucp / uusel < prev   
Encoding:
Text File  |  1997-08-26  |  5.4 KB  |  255 lines

  1. #!/usr/lib/oa/utilbin/oash
  2. # @(#) uusel.oash 1.0 96/01/20
  3. # 92/09/21 John H. DuBois III (john@armory.com)
  4. # 92/09/24 run uujobs outside of curses so that error messages will be
  5. #          printed correctly; truncate uujobs
  6. # 92/10/26 Made ViewData and MoveJobs work
  7. # 92/11/23 Made uucp_kill work; deal with X.* files; added EditControl
  8. # 93/11/23 Note in selection header that only 5 jobs can be selected.
  9. #          Let system names be given on command line.
  10. #          Remove $TMP before explicit exit
  11. # 96/01/20 Use tmpdir env vars if set
  12.  
  13. OALIB=${OALIB-"/usr/lib/oa"}
  14. PATH=$OALIB/utilbin:$PATH
  15.  
  16. # run ourself thru oash 
  17. oadeinit 2>/dev/null || exec oash $0 "$@"
  18.  
  19. . `findfile shell_strs`
  20.  
  21. : ${TMP:=$TMPDIR}
  22. : ${TMP:=/tmp}
  23. TmpPref=$TMP/#uusel.$$
  24. ActionTmp=$TmpPref.p
  25. ViewFileWin=3
  26. [ -z "$LINES" ] && LINES=`tput lines`
  27. LINES2=`expr $LINES - 2`
  28.  
  29. CloseWindow() {
  30.     wmove 0
  31.     wmclose $1
  32. }
  33.  
  34. # Print a message centered on the screen.
  35. # Usage: WinMessage "message" ["title"]
  36. # If no title is given, the window has no title.
  37. # WinMessage wait for the use to press <esc>,
  38. # then closes the window and returns.
  39. WinMessage() {
  40.     Message=$1
  41.     Title=$2
  42.     Length=`expr length "$Message" + 2`
  43.     [ $Length -lt 30 ] && Length=30
  44.     Clean_wmopen 38 3 $Length 10
  45.     [ $# -gt 1 ] && wmtitle "$Title"
  46.     wmmessage -r "press <return> to continue"
  47.     echo "$Message"
  48.     wrefresh 38
  49.     read garbage
  50.     CloseWindow 38
  51. }
  52.  
  53. # Usage: Centered_wmopen num lines cols top_row
  54. # Creates a window centered on column 38/39
  55. Centered_wmopen() {
  56.     wmopen $1 $2 $3 $4 `expr 39 - $3 / 2`
  57. }
  58.  
  59. # Usage: Clean_wmopen num lines cols top_row
  60. # Creates a window centered on column 38/39 and clears a border around it.
  61. # Uses window #30 to clear.
  62. Clean_wmopen() {
  63.     N=$1 L=$2 C=$3 X=$4
  64.     set `ksh -c "echo $(($L+2)) $(($C+2)) $(($X-1)) $((38-$C/2)) $((39-$C/2))"`
  65.     newwin 30 $1 $2 $3 $4
  66.     wmclose 30
  67.     wmopen $N $L $C $X $5
  68. }
  69.  
  70. # Usage: ViewFile filename
  71. # Sets LAST_KEY
  72. ViewFile() {
  73.     ViewFileFile=$1
  74.     wmopen $ViewFileWin $LINES2 78 0 0
  75.     if [ -d "$ViewFileFile" ]; then
  76.     wmtitle "Viewing directory: $ViewFileFile"
  77.     l -RA "$ViewFileFile" > $DirList
  78.     ViewF=$DirList
  79.     else
  80.     wmtitle "Viewing file: $ViewFileFile"
  81.     ViewF=$ViewFileFile
  82.     fi
  83.     wmmessage -r "Use arrow keys, <esc> when done"
  84.     scan -e"$EOFMSG" "$ViewF"
  85.     CloseWindow $ViewFileWin
  86. }
  87.  
  88. uucp_kill() {
  89.     oadeinit
  90.     for job
  91.     do
  92.     uustat -k "$job"
  93.     done
  94. }
  95.  
  96. ControlFiles() {
  97.     # Do this with a separate sh to avoid output-expensive oainit
  98.     sh -c '
  99.     NoLine=-n
  100.     for job in "$@"
  101.     do
  102.     echo $NoLine ""
  103.     unset NoLine
  104.     set -- */[CX].$job
  105.     if [ -f $1 ]; then
  106.         echo $1:
  107.         cat $1
  108.     else 
  109.         echo "Could not find control file C.$job or X.$job."
  110.     fi
  111.     done > '" $ActionTmp" "$@"
  112.     wmopen 3 $LINES2 78 0 0
  113.     wmtitle "Control Files"
  114.     wmmessage -r "Use arrow keys, <esc> when done"
  115.     scan -e"$EOFMSG" $ActionTmp
  116.     CloseWindow 3
  117. }
  118.  
  119. EditControl() {
  120.     # "edit" cmd fails miserably, so use $VISUAL etc.
  121.     if [ -z "$VISUAL" ]; then
  122.     if [ -n "$EDITOR" ]; then
  123.         VISUAL=$EDITOR
  124.     else
  125.         VISUAL=vi
  126.     fi
  127.     fi
  128.     EdList=
  129.     for job
  130.     do
  131.     set -- */[CX].$job
  132.     EdList="$EdList $*"
  133.     done
  134.     oadeinit
  135.     $VISUAL $EdList
  136.     oainit
  137. }
  138.  
  139. ViewData() {
  140.     set -- `uujobs +dj "$@"`
  141.     for file
  142.     do
  143.     case "$file" in
  144.     D.*)
  145.         if [ -r */$file ]; then
  146.         ViewFile */$file
  147.         else
  148.         WinMessage "Cannot open $file"
  149.         fi;;
  150.     esac
  151.     done
  152. }
  153.  
  154. MoveJobs() {
  155.     oadeinit
  156.     OFS=$IFS
  157.     for job
  158.     do
  159.     if [ */[CX].$job = "*/[CX].$job" ]; then
  160.         echo "[CX].$job not found." 1>&2
  161.         continue
  162.     fi
  163.     set -- */[CX].$job
  164.     IFS=/
  165.     set -- $1
  166.     IFS=$OFS
  167.     echo mv $1/$2 $1/.$2
  168.     mv $1/$2 $1/.$2
  169.     done
  170.     echo "Move control files back to allow processing of the jobs."
  171. }
  172.  
  173. Action() {
  174.     while :; do
  175.     Clean_wmopen 2 8 30 8
  176.     wmtitle "Select Action"
  177.     wmmessage -r "<esc> to return"
  178.     pp Kill  "View Data Files" \
  179.     "View Control Files" "Move Control Files" "Edit Control Files" Quit
  180.     [ $PP_NUM -lt 0 ] && return 1
  181.     case $PP_ITEM in
  182.     Kill) 
  183.         uucp_kill $Jobs; return 0;;
  184.     Move*)
  185.         MoveJobs $Jobs; return 0;;
  186.     "View Data"*)
  187.         ViewData $Jobs;;
  188.     "View Control"*)
  189.         ControlFiles $Jobs;;
  190.     Edit*)
  191.         EditControl $Jobs;;
  192.     Quit)
  193.         return 0;;
  194.     esac
  195.     done
  196. }
  197.  
  198. # Add a non-visible character to the end of each line so that multiple
  199. # selected lines can be distinguished.
  200. # First replace any of the chars with spaces to prevent confusion.
  201. # Tab and various other chars cause various problems so use backspace.
  202. # Truncate lines because pp fails on long lines.
  203. Sep=""
  204. # oash does not seem to like "$@"... expands to "" even when $# is 0???
  205. uujobs +w80 +s ++ $* | sed "s/$Sep/ /g;s/$/ $Sep/" > $TmpPref
  206.  
  207. {
  208.     read header
  209.     read line
  210.     if [ -z "$line" ]; then
  211.     echo "No UUCP jobs queued."
  212.     rm -f "$TmpPref"
  213.     exit 1
  214.     fi
  215. } < $TmpPref || exit 0
  216.  
  217. # start of main code
  218.  
  219. oainit
  220.  
  221. cd /usr/spool/uucp
  222.  
  223. while :; do
  224.     wmopen 1 $LINES2 78 0 0
  225.     wmtitle "Select up to five UUCP Jobs"
  226.     wmmessage -r \
  227. "Use arrow keys; <space> selects; <Return> when done selecting; <esc> to quit"
  228.     pp -m -f $TmpPref
  229.     [ -z "$PP_ITEM" ] && break
  230.     
  231.     set -f
  232.  
  233.     OIFS=$IFS
  234.     IFS="$Sep"
  235.     set -- $PP_ITEM
  236.     IFS=$OIFS
  237.     unset Jobs
  238.  
  239.     for line
  240.     do
  241.     if [ -n "$line" ]; then
  242.         set -- $line
  243.         # Ignore header if it was selected for some silly reason
  244.         [ -n "$line" -a "$line" != " " -a "$1" != Job ] && Jobs="$Jobs $1"
  245.     fi
  246.     done
  247.  
  248.     set +f
  249.  
  250.     Action && break
  251. done
  252.  
  253. oadeinit
  254. rm -f $TmpPref $ActionTmp
  255.